//
//  MyQRCodeViewController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/10.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "MyQRCodeViewController.h"
#import "QRCodeTool.h"

@interface MyQRCodeViewController ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIView *QRCodeBgView;
@property (weak, nonatomic) IBOutlet UIImageView *qrCodeImg;

@end

@implementation MyQRCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configQRCode];
    // Do any additional setup after loading the view from its nib.
}

- (void)setupUI{
    [super setupUI];
    self.title = LCLocalString(@"my_qrcode");
    LRViewBorderRadius(self.bgView, 10, 0, [UIColor clearColor]);
    LRViewBorderRadius(self.QRCodeBgView, 5, 0, [UIColor clearColor]);
}

- (void)configQRCode{
    UserInfoModel *user = kAppDelegate.curUser;
    self.qrCodeImg.image = [QRCodeTool getQRCodeImg:user.hid];
}
- (IBAction)saveAction:(id)sender {
    if (self.qrCodeImg.image) {
        UIImageWriteToSavedPhotosAlbum(self.qrCodeImg.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }
}


#pragma mark -- <保存到相册>
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    NSString *msg = nil ;
    if(error){
        msg = @"保存图片失败" ;
    }else{
        msg = @"保存图片成功" ;
    }
    LCInfoHUD(msg, 1);
}

@end
